/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package main;

import aso.upna.playlist.GenericList;
import cliente.ClientThread;
import java.net.Socket;
import aso.upna.rmi.ServidorRmi;

/**
 *
 * @author triki
 */
public class Main {

    public static void main(String args[])
    {
        int i=0;

        GenericList user_list = new GenericList();
        Servidor server = new Servidor(5,6666,"./shared/");
        ServidorRmi rmi = new ServidorRmi(1084);

        server.startServer();
        rmi.start();
        
        while(true)
        {
            System.out.println("> Esperando clientes...");
            Socket client = server.acceptClient();
            System.out.println("> Cliente aceptado");
            System.out.print("path: "+server.getPathBase());
            ClientThread client_t = new ClientThread(client,server.getUserLookUp(),server.getUserRegistry(),server.getPathBase());
            //Si el numero de cliente supera al permitido -> rechazamos la conexion.
            if(user_list.getCountElements() > server.getMaxUsersAccepted())
                client_t.rejectUser();

            Thread t_client = new Thread(client_t);
            System.out.print("> Lanzando el hilo del cliente...");
            t_client.start();
        }
    }
}
